import fileUpload from "@/components/file-upload.vue"
import { PayOptions, TypeOptions,priorityOptions,relevancyOptions } from "../bill/constant"
import { getOptions } from "@/apis/sales"
import { orderStatis } from "@/apis/order"
import store from "@/store"
import { groupDate } from "@/apis/shop"
import dayjs from "dayjs"

export default async (that)=>{
	let {data:dateList} = await groupDate()
	console.log(dateList)
	function cellClassName(date){
		let d = dayjs(date).format("YYYY-MM-DD")
		// console.log(d)
		if(dateList.includes(d)){
			return "badge"
		}
	}
	getOptions().then(res=>{
		store.commit("option/setSalesman",res.data)
	})
	return {
		columns:[
			 
			{
				key:"shopName",
				label:"店铺名",
				slot:"shopName",
				width:400,
		 
			},
			{
				key:"platform",
				label:"平台类型",
				slot:"platform",
				width:100,
			},
			{
				key:"salesName",
				label:"所属销售",
				width:100,
			},
			{
				key:"orderCount",
				label:"统计单数",
				headerSlot:"statisCount",
			},
			{
				key:"orderMoney",
				label:"统计金额",
				headerSlot:"statisMoney",
			},
			{
				key:"waitPayCount",
				label:"账单数",
				width:100,
			},
			// {
			// 	key:"createTime",
			// 	label:"创建时间"
			// },
			// {
			// 	key:"updateTime",
			// 	label:"修改时间"
			// },
			{
				key:"operation",
				label:"操作",
				slot:"operation",
				width:500,
				removeBtn:{
					show:true,
					permission:"shop:delete"
				},
				editBtn:{
					show:true,
					permission:"shop:edit"
				},
			}
		],
		reqOptions:{
			list:{
				method:"get",
				url:"/shop",
				callback(that){
					let form = that.search.form || {}
					console.log(form)
					orderStatis(form).then(res=>{
						console.log("统计",res)
						that.$emit("updateStatis",res.data)
					})
					groupDate(form).then(res=>{
						dateList = res.data
					})
				}       
			},
			insert:{
				method:"post",
				url:"/shop"
			},
			update:{
				method:"put",
				url:"/shop"
			},
			remove:{
				method:"delete",
				url:"/shop/${id}"
			}
		},
		search:{
			form:{},
			options:[
				
				{
					key:"shopName",
					type:"el-input",
					label:"店名",
					width:"400px",
					required:false,
					props:{
						clearable:true
					}
    
				},

				{
					key:"platform",
					type:"el-select",
					label:"平台类型",
					required:false,
					options:TypeOptions,
					props:{
						clearable:true
					}
				},
				{
					key:"sid",
					type:"el-select",
					label:"所属销售",
					permission:"shop:filter",
					readStore:"salesman",
					required:false,
					props:{
						clearable:true,
					}
    
				},
				{
					key:"activeDate",
					label:"活动日期",
					type:"el-date-picker",
					props:{
						type:"date",
						format:"yyyy-MM-dd",
						"value-format":"yyyy-MM-dd",
						"popper-class":"picker-popper",
						"picker-options":{
							cellClassName:cellClassName
						}
					},
					required:false
				},
				{
					key:"status",
					type:"el-select",
					label:"支付状态",
					options:PayOptions,
					required:false,
					props:{
						clearable:true
					}
    
				},
				
				{
					key:"startTime",
					label:"时间范围",
					type:"el-date-picker",
					width:"140px",
					props:{
						type:"date",
						format:"yyyy-MM-dd",
						"value-format":"yyyy-MM-dd",
						placeholder:"开始时间"
					},
					// required:true
				},
				{
					key:"endTime",
					label:"",
					type:"el-date-picker",
					width:"140px",
					props:{
						type:"date",
						format:"yyyy-MM-dd",
						"value-format":"yyyy-MM-dd",
						placeholder:"结束时间"

					},
					// required:true
				},
				{
					key:"priority",
					type:"el-select",
					label:"标注状态",
					options:priorityOptions,
					required:false,
					props:{
						clearable:true
					}
    
				},{
					key:"isrelevancy",
					type:"el-select",
					label:"关联状态",
					options:relevancyOptions,
					required:false,
					props:{
						clearable:true
					}
    
				},{
					key:"relevancy",
					type:"el-input",
					label:"关联店名",
					width:"200px",
					required:false,
					props:{
						clearable:true
					}
    
				},

				{
					key:"test",
					type:"el-button",
					label:"查询",
					removeLabel:true,
					width:false,
					props:{
						type:"primary",
						// size:"medium"
					},
					listeners:{
						click(...e){
							that.searchFun && that.searchFun instanceof Function && that.searchFun(...e)
							that.$emit("search")
							console.log("click")
							that.getList()
						}
					}
				},
				
			],
			direction:"h",
			labelPosition:"right"
		},
		operation:{
			form:{},
			direction:"h",
			options:[
				{
					key:"btn1",
					type:"el-button",
					label:"添加",
					width:false,
					removeLabel:true,
					props:{
						type:"primary",
						// size:"medium",
						icon:"el-icon-plus"
					},
					listeners:{
						click:(...e)=>{
							console.log(that)
							that.addFun && that.addFun instanceof Function && that.addFun(...e)
						}
					}
				},
				{
					key:"batchChange",
					type:"el-button",
					label:"批量修改订单状态",
					slot:"batchChange",
					width:false,
					removeLabel:true,
					props:{
						type:"danger",
						size:"mini",
					},
				}
			]
		},
		updateField:async (form={platform:1})=>{
			return {
				form,
				direction:"h",
				options:[
					{
						key:"shopName",
						label:"店名 ",
						type:"el-input",
						required:true
					},
					{
						key:"platform",
						label:"平台类型",
						type:"el-select",
						required:true,
						options:TypeOptions
					},
					{
						key:"sid",
						type:"el-select",
						label:"所属销售",
						readStore:"salesman",
						required:false,
						props:{
							clearable:true
						}
		
					},
					// {
					// 	key:"isDefault",
					// 	label:"是否默认",
					// 	type:"el-switch",
					// 	props:{
					// 		activeValue:1,
					// 		inactiveValue:0
					// 	}
					// }
                    
				]
			}
		},
		config:{
			table:{
				checkbox:true, 
			},
		}
	}
}